package com.action.log;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.beans.log.LogFavorite;
import com.business.log.LogFavorBus;
import com.config.SystemGlobals;

public class ManageFavor extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String contentType = SystemGlobals.getValue("contentType");
		PrintWriter out = response.getWriter();
		response.setContentType(contentType);

		if (request.getParameter("deleted") != null) {
			String[] favorNos = request.getParameterValues("deleted");
			LogFavorBus lfb = new LogFavorBus();
			for (int i = 0; i < favorNos.length; i++) {
				lfb.del(favorNos[i]);
			}
			out
					.println("<script>alert(\"删除选定的收藏信息\");window.location=\"admin/blog/favorlist.jsp\";</script>");
			out.close();
		}
		if (request.getParameter("edit") != null) {
			String favInfo = request.getParameter("favinfo");
			String favName=request.getParameter("favname");
			String favAddTime = request.getParameter("favaddtime");
			String username = request.getParameter("username");
			String logNo = request.getParameter("logno");
			LogFavorite lf = new LogFavorite();
			lf.setFavAddTime(favAddTime);
			lf.setFavInfo(favInfo);
			lf.setFavName(favName);
			lf.setLogNo(logNo);
			lf.setUsername(username);

			String favorNo = request.getParameter("no");
			LogFavorBus lfb = new LogFavorBus();
			lfb.update(lf, favorNo);
			out
					.println("<script>alert(\"您成功地编辑了收藏信息\");window.location=\"admin/blog/favorlist.jsp\";</script>");
			out.close();
		}
	}

}
